<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>mrdForm</title>
    <link rel="stylesheet" type="text/css" href="../css/jquery/jquery-ui-1.8.23.custom.css"
          media="screen"/>
    <link rel="stylesheet" type="text/css" href="../css/jqgrid/ui.jqgrid.css" media="screen"/>
    <jsp:include page="../../../head.jsp"/>
</head>
<script type="text/javascript">
    $(function () {
        var deptId = $("#deptId").val();
        if (deptId == "") {
            deptId = "${deptId}";
        }
        $("#mrdForm").mrdForm({
                                  title: "查询列表",// 表单标题
                                  columns: [{
                                      name: "name",
                                      label: "用户名称"
                                  }],
                                  buttons: {
                                      'custom': [
                                          {id: "addDept", value: "添加用户", click: add},
                                          {id: "modify", value: "编辑用户", click: edit},
                                          {id: "deleteUser", value: "删除用户", click: delUser},
                                      ]
                                  },
                                  grid: {
                                      id: "columnGrid",
                                      url: "company-listUser?dept.id=" + deptId,
                                      colNames: ["id", "用户名", "手机号码", "启用模式", "状态"],
                                      colModel: [{
                                          name: 'id',
                                          index: 'id',
                                          hidden: true,
                                          align: "center"
                                      }, {
                                          name: 'name',
                                          index: 'name',
                                          label: "用户名",
                                          width: 70,
                                          align: "center"
                                      }, {
                                          name: 'mobile',
                                          index: 'mobile',
                                          label: "手机号码",
                                          width: 100,
                                          align: "center"
                                      }, {
                                          name: 'isabled',
                                          index: 'isabled',
                                          label: "启用模式",
                                          width: 70,
                                          align: "center",
                                          //字段值的显示格式转换
                                          formatter: function (cellvalue, options, row) {
                                              if (cellvalue == "1") {
                                                  return "禁用";
                                              } else if (cellvalue == "0") {
                                                  return "启用";
                                              }
                                          }
                                      }, {
                                          name: 'state',
                                          index: 'state',
                                          label: "状态",
                                          width: 50,
                                          align: "center",
                                          //字段值的显示格式转换
                                          formatter: function (cellvalue, options, row) {
                                              if (cellvalue == "1") {
                                                  return "删除";
                                              } else if (cellvalue == "0") {
                                                  return "可用";
                                              }
                                          }
                                      }],
                                      title: "用户列表",
                                      sortname: "ctime",
                                      //rowNum:5,
                                      jsonReader: {
                                          //从哪个json对象中取值
                                          root: "users"
                                      },
                                      onSelectRow: function (id) {
                                          //parent.document.getElementById("rightFrame").src="../base/company-mainUser?dept.id="+id;
                                      },
                                      ondblClickRow: function (id) {
                                          location.href =
                                                  "company-manageUser?user.id=" + id + "&dept.id="
                                                  + $("#deptId").val();
                                      }
                                  }
                              });
        $("#mrdForm").mrdForm("resize");
    });
    //添加
    var add = function () {
        location.href = "../base/company-manageUser?dept.id=" + $("#deptId").val();
    };
    var del = function () {
    };
    //编辑
    var edit = function () {
        var selected_rowid = $("#columnGrid").jqGrid("getGridParam", "selrow");
        if (!selected_rowid || selected_rowid == "" || selected_rowid == null) {
            alert("请选择需要编辑的用户");
            return;
        }
        var rowData = $("#columnGrid").getRowData(selected_rowid);
        var userId = rowData.id;
        location.href =
                "../base/company-manageUser?user.id=" + userId + "&dept.id=" + $("#deptId").val();
    };
    //删除
    var delUser = function () {
        var selected_rowid = $("#columnGrid").jqGrid("getGridParam", "selrow");
        if (!selected_rowid || selected_rowid == "" || selected_rowid == null) {
            alert("请选择需要删除的用户");
            return;
        }
        var rowData = $("#columnGrid").getRowData(selected_rowid);
        var userId = rowData.id;
        $.ajax({
                   url: "company-delUser?userId="
                        + userId,
                   async: false,
                   cache: false,
                   success: function (data) {
                   }
               });
    }
</script>
<body>
<input type="hidden" id="deptId" value='${deptId}'/>
<div id="mrdForm"></div>
</body>
</html>
